package com.cqs.leetcode.search;

import java.util.Random;

public class FirstBadVersion278 {

    public int firstBadVersion(int n) {
        int left = 1, right = n;
        while (left < right) {
            int mid = (right - left) / 2 + left;
            if (isBadVersion(mid)) {//bad version
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }


    boolean isBadVersion(int n) {
        System.out.println("random:" + random);
        return n >= random;
    }

    int random = new Random().nextInt(Integer.MAX_VALUE);

    public static void main(String[] args) {
        FirstBadVersion278 f = new FirstBadVersion278();
        int badVersion = f.firstBadVersion(Integer.MAX_VALUE);
        System.out.println(badVersion);
    }
}
